import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import '../utils/http.dart';
//登录注册公用组件
import './common.dart';

class Register extends StatefulWidget {
  Register({Key? key, arguments}) : super(key: key);

  @override
  _RegisterState createState() => _RegisterState();
}

class _RegisterState extends State<Register> {
  // var flag = false;
  // FocusNode phoneFocusNode = FocusNode();
  // FocusNode yzmFocusNode = FocusNode();
  String phone = '15889476453';
  String verification = '9527';
  String inviteCode = '';
  bool flag = false;

  // 手机号改变
  void onChangedPhone(val) {
    print(val);
    setState(() {
      phone = val;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Column(
          children: [
            LoginHeader(name: "login"),
            SizedBox(
              height: 30,
            ),
            Padding(
              padding: EdgeInsets.all(20),
              child: Column(
                children: [
                  InputAdds(
                      phones: phone,
                      callBack: (value) => onChangedPhone(value)),
                  SizedBox(
                    height: 10,
                  ),
                  // Divider(color:Colors.white ,),
                  InputYzm(
                    yzm: verification,
                    phone: phone,
                    callBack: (val) {
                      print(val);
                      setState(() {
                        verification = val;
                      });
                    }),
                  SizedBox(
                    height: 10,
                  ),
                  InputInvite(
                    invites: inviteCode,
                    callBack: (val) {
                      print(val);
                      setState(() {
                        inviteCode = val;
                      });
                    }),

                  Protocol(callBack: (val) {
                    print(val);
                    setState(() {
                      flag = val;
                    });
                  }),
                  SizedBox(
                    height: 40,
                  ),
                  Container(
                    width: double.infinity,
                    height: 50,
                    child: OnButton(name:"登录",callBack: (){
                      if (verification == '' || phone == '' || inviteCode == '') {
                            EasyLoading.showToast("输入不能为空");
                            return;
                          }
                          if (verification.length != 4) {
                            EasyLoading.showToast("验证码错误");
                            return;
                          }
                          if (!flag) {
                            EasyLoading.showToast("请阅读用户协议");
                            return;
                          }
                          if (!Yz().isPhone(phone)) {
                            return;
                          }

                          Navigator.pushNamed(context, '/');
                    }),
                  ),
                  SizedBox(
                    height: 40,
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
